﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Interactivity;

namespace EmraldClient
{
  public class DropFileBehavior : Behavior<FrameworkElement>
  {
    protected override void OnAttached()
    {
      AssociatedObject.Drop += AssociatedObjectOnDrop;
    }
    protected override void OnDetaching()
    {
      AssociatedObject.Drop -= AssociatedObjectOnDrop;
    }

    private void AssociatedObjectOnDrop(object sender, DragEventArgs dragEventArgs)
    {
      var filesDropTarget = AssociatedObject.DataContext as IFilesDropTarget;
      if (filesDropTarget == null) return;
      filesDropTarget.Drop((string[])
        dragEventArgs.Data.GetData(DataFormats.FileDrop));
    }
  }
}
